﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Search : System.Web.UI.PageEx
{
    private DataSet ds = null;
    private int iPageCount = 0;
    private int iRecordCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //绑定菜单
            rptClassMenu.DataSource = DalEx.DbClassEx.Select(" and cStatus=1 and cType=0 and cLevel=0 order by cOrder asc,cId desc");
            rptClassMenu.DataBind();
            DataBinds();
        }
    }
    private void DataBinds()
    {
        Model.DbSystem dbSystem = DalEx.DbSystemEx.Select(1);
        if (dbSystem != null)
        {
            setMeta("信息资料查询", dbSystem.SKeywords, dbSystem.SDescription);
        }

        string strQuery = string.Empty;
        string strKeywords = Convert.ToString(Request.QueryString["Keywords"]);
        if (strKeywords != null)
        { 
            strKeywords = HttpUtility.UrlDecode(strKeywords);
            lblShowTitle.Text = strKeywords;            
            strQuery = " and (aTitle like '%" + strKeywords + "%' or aKeywords like '%" + strKeywords + "%' or aNote like '%" + strKeywords + "%')";
        }
        ds = WebBase.Comm.SelectByPage("dbArticles ", "*", "aId", strQuery + " and aStatus=1", anpProduct.PageSize, anpProduct.CurrentPageIndex, "aOrder", 0, out iPageCount, out iRecordCount);
        anpProduct.RecordCount = iRecordCount;
        rptNewsList.DataSource = ds;
        rptNewsList.DataBind();
    }
    protected void anpProduct_PageChanged(object sender, EventArgs e)
    {
        DataBinds();
    }
    private void setMeta(string title, string key, string des)
    {
        string strWebTitle = string.Empty, strWebKeywords = string.Empty, strWebDescription = string.Empty;
        Model.DbSystem dbSystem = Dal.DbSystemDal.Select(1);
        if (dbSystem != null)
        {
            strWebTitle = dbSystem.STitle;
            strWebKeywords = dbSystem.SKeywords;
            strWebDescription = dbSystem.SDescription;
        }
        HtmlMeta keywords = new HtmlMeta(); // keywords
        HtmlMeta description = new HtmlMeta(); // description
        keywords.Name = "keywords";
        keywords.Content = string.IsNullOrEmpty(key) ? strWebKeywords : key;

        this.Title = string.IsNullOrEmpty(title) ? strWebTitle : title;

        description.Name = "description";
        description.Content = string.IsNullOrEmpty(des) ? strWebDescription : des;

        Page.Header.Controls.Add(keywords);
        Page.Header.Controls.Add(description);
    }
    protected string GetPageName(object objValue)
    {
        string strResult = string.Empty;
        string strValue = Convert.ToString(objValue);
        switch (strValue)
        { 
            case "News":
                strResult = "NewsDetail.aspx";
                break;
            case "Course":
                strResult = "CourseDetail.aspx";
                break;
            case "Products":
                strResult = "ProductsDetail.aspx";
                break;
        }
        return strResult;
    }
    protected string GetClassName(object objValue,object objClassIds)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        Model.DbClass dbClass = DalEx.DbClassEx.Select(iValue);
        if (dbClass != null)
        {
            //switch (dbClass.CType)
            //{
            //    case 0:
            //        strResult = "【<a href=\"News.aspx?ClassId=" + Convert.ToString(objClassIds) + "\">" + dbClass.CName + "</a>】";
            //        break;
            //    case 1:
            //        strResult = "【<a href=\"Products.aspx?ClassId=" + Convert.ToString(objClassIds) + "\">" + dbClass.CName + "</a>】";
            //        break;
            //    case 2:
            //        strResult = "【<a href=\"CourseSystem.aspx?ClassId=" + Convert.ToString(objClassIds) + "\">" + dbClass.CName + "</a>】";
            //        break;
            //}
            switch (dbClass.CType)
            {
                case 0:
                    strResult = "【" + dbClass.CName + "】";
                    break;
                case 1:
                    strResult = "【" + dbClass.CName + "】";
                    break;
                case 2:
                    strResult = "【" + dbClass.CName + "】";
                    break;
            }

        }
        return strResult;
    }
}